<template>
  <div class="list-table">
    <!--    <div class="area-header">-->
    <!--      <span class="area-header-title">{{ $t('上会管理') }}</span>-->
    <!--    </div>-->
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('会议类型')" prop="meetingType">
        <dict-select v-model="queryParams.meetingType" :placeholder="$t('会议类型')" dictionary="mt_type" />
      </el-form-item>
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input v-model="queryParams.dealName" :placeholder="$t('项目名称')" clearable @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('投资主体')" prop="fundName">
        <el-input v-model="queryParams.fundName" :placeholder="$t('投资主体')" clearable @keyup.enter.native="queryHandle" />
      </el-form-item>
      <el-form-item :label="$t('会议结论')" prop="mtConclusion">
        <el-select v-model="queryParams.mtConclusion" clearable :placeholder="$t('会议结论')" @keyup.enter.native="queryHandle">
          <el-option
            v-for="dict in mtConclusionOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          v-hasPermi="['meeting:info:edit']"-->
    <!--          type="primary"-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="addHandle"-->
    <!--        >{{ $t('新增') }}</el-button>-->
    <!--      </el-col>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="mtArrangeInfoList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议类型')" align="center" prop="meetingType" :formatter="meetingTypeFormat" />
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" />
      <el-table-column :label="$t('项目负责人')" align="center" prop="personChargeName" />
      <el-table-column :label="$t('会议日期')" align="center" prop="mtDate">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.mtDate,'{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议时间')" align="center" prop="mtTime" />
      <el-table-column :label="$t('投资主体')" align="center" prop="fundName" />
      <el-table-column :label="$t('预计投资金额') + $t('金额单位')" align="center" prop="investAmount">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.investAmount,'w',2,true) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议结论')" align="center" prop="mtConclusion" :formatter="mtConclusionFormat" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" min-width="220">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.voteFlag === 'Y' ? (scope.row.delFlag === '0' && (scope.row.voteStatus === 'N' || !scope.row.voteStatus)) : scope.row.delFlag === '0' && scope.row.conclusionStatus === 'N'"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-if="scope.row.voteFlag === 'Y' && (scope.row.commentStatus === 'N' || !scope.row.commentStatus)"
            size="small"
            type="text"
            icon="el-icon-tickets"
            @click="updateVoteHandle(scope.row)"
          >{{ $t(scope.row.voteStatus === 'D' ? '投票中' : (scope.row.voteStatus === 'W' ? '重新投票' : '发起投票')) }}</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="mtConclusionHandle(scope.row)"
          >{{ $t('结论') }}</el-button>
          <el-button
            v-hasPermi="['meeting:info:view']"
            size="small"
            type="text"
            icon="el-icon-view"
            @click="viewHandle(scope.row)"
          >{{ $t('详情') }}</el-button>
          <el-button
            v-if="scope.row.voteFlag === 'Y' ? (scope.row.delFlag === '0' && (scope.row.voteStatus === 'N' || !scope.row.voteStatus)) : scope.row.delFlag === '0' && scope.row.conclusionStatus === 'N'"
            v-hasPermi="['meeting:info:edit']"
            size="small"
            type="text"
            icon="el-icon-close"
            @click="updateClose(scope.row)"
          >{{ $t('取消会议') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改排会信息对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtArrangeInfoForm ref="mtArrangeInfoForm" />
    </el-dialog>
    <!-- 发起投票对话框 -->
    <el-dialog :title="$t('投票信息')" :visible.sync="voteFormOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtVoteForm ref="mtVoteForm" />
    </el-dialog>
    <!-- 添加或修改会议结论对话框 -->
    <el-dialog :title="$t(mtConclusionTitle)" :visible.sync="mtConclusionOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtConclusionForm ref="mtConclusionForm" :meeting-id="form.meetingId" />
    </el-dialog>
    <!-- 添加或修改会议结论对话框 -->
    <el-dialog :title="$t('会议详情')" :visible.sync="mtDetailOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mt-detail ref="MtDetails" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listMtArrangeInfo,
  delMtArrangeInfo,
  exportMtArrangeInfo,
  updateCloseFlag
} from '@/api/meeting/info/mtArrangeInfo'
import mtArrangeInfoForm from './mtArrangeInfoForm.vue'
import mtConclusionForm from '../conclusion/mtConclusionForm.vue'
import { moneyFormat, parseTime } from '../../../../utils/ruoyi'
import mtDetail from '../indexForm.vue'
import MtVoteForm from '@/views/deal/mt/vote/mtVoteForm.vue'
export default {
  components: {
    MtVoteForm,
    mtArrangeInfoForm,
    mtConclusionForm,
    mtDetail
  },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 排会信息表格数据
          mtArrangeInfoList: [],
          // 弹出层标题
          title: '上会管理',
          // 会议结论弹出标题
          mtConclusionTitle: '会议结论',
          // 是否显示弹出层
          formOpen: false,
          // 会议结论
          mtConclusionOpen: false,
        // 投票
        voteFormOpen: false,
        // 会议详情
        mtDetailOpen: false,
          // 查询参数
          queryParams: {
              meetingId: undefined,
              dealId: undefined,
              companyId: undefined,
              mtDate: undefined,
              mtTime: undefined,
              mtMinutesPerson: undefined,
              regularAttendees: undefined,
              dealTeamMembers: undefined,
              innerMember: undefined,
              outerMember: undefined,
              outerEmail: undefined,
              mtAddress: undefined,
              sendUser: undefined,
              ccUser: undefined,
              actTitle: undefined,
              applyContent: undefined,
              pageNum: 1,
              pageSize: 10,
            dealName: undefined,
            fundName: undefined,
            orderByColumn: 'a.mt_date desc',
            mtConclusion: undefined
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {},
        meetingTypeOptions: [],
        mtConclusionOptions: []
      }
  },
  created() {
      this.getDicts('mt_type').then(res => {
        this.meetingTypeOptions = res.data
      })
      this.getDicts('mt_conclusion').then(res => {
        this.mtConclusionOptions = res.data
        console.log(res.data, 'res.data')
        const nullMt = {
            id: 1,
            dictLabel: '空',
            dictValue: 'null'
        }
        this.mtConclusionOptions.push(nullMt)
      })
      this.getList()
  },
  methods: {
    parseTime,
    moneyFormat,
    /** 查询排会信息列表 */
    getList() {
        this.loading = true
        listMtArrangeInfo(this.queryParams).then(response => {
            this.mtArrangeInfoList = response.rows
            this.total = response.total
            this.loading = false
        }).catch(() => {
            this.loading = false
        })
    },

    meetingTypeFormat(row) {
      return this.selectDictLabel(this.meetingTypeOptions, row.meetingType)
    },
    mtConclusionFormat(row) {
      return this.selectDictLabel(this.mtConclusionOptions, row.mtConclusion)
    },
    // 发起投票
    updateVoteHandle(row) {
      var obj = {
        id: row.meetingId,
        showBtn: true,
        process: row.voteStatus !== 'D'
      }
      this.voteFormOpen = true
      this.$nextTick(() => {
        this.$refs.mtVoteForm.init(obj)
      })
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            meetingId: undefined,
            dealId: undefined,
            companyId: undefined,
            mtDate: undefined,
            mtTime: undefined,
            mtMinutesPerson: undefined,
            regularAttendees: undefined,
            dealTeamMembers: undefined,
            innerMember: undefined,
            outerMember: undefined,
            outerEmail: undefined,
            mtAddress: undefined,
            sendUser: undefined,
            ccUser: undefined,
            actTitle: undefined,
            applyContent: undefined,
            remark: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined,
          dealName: undefined,
          fundName: undefined
        }
        this.resetForm('form')
    },
    // 查看详情
    viewHandle(row) {
      this.mtDetailOpen = true
      this.$nextTick(() => {
        var obj = {
          id: row.meetingId
        }
        console.log(this.$refs.MtDetails)
        this.$refs.MtDetails.init(obj)
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.mtArrangeInfoForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        console.log(row, '修改')
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.mtArrangeInfoForm.init(row)
        })
    },
    /* 取消会议 */
    updateClose(row) {
      if (row.meetingId) {
        this.$confirm(this.$t('会议取消后，该上会记录会重新返回排会池，是否取消会议？'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: 'warning'
        }).then(() => {
          return updateCloseFlag(row.meetingId)
        }).then(() => {
          this.$message.success(this.$t('会议已取消'))
          this.getList()
        })
      }
    },
    /** 会议结论按钮操作 */
    mtConclusionHandle(row) {
      this.mtConclusionOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.mtConclusionForm.init(row)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return delMtArrangeInfo(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(() => {
            this.loading = false
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(() => {
            return exportMtArrangeInfo(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(() => {
        })
    }
  }
}
</script>

